<template>
  <div class="rank_top" :style="[rowShowCountCpd]">
    <div class="header">
      <p class="title">{{ item.name }}</p>
    </div>
    <div class="content">
      <div class="poster">
        <ltAvatar :src="item.tracks[0].al.picUrl" :size="100" class="one"></ltAvatar>
        <ltAvatar :src="item.tracks[1].al.picUrl" :size="100" class="two"></ltAvatar>
      </div>

      <div class="list">
        <template v-for="(i, inedx) in item.tracks.slice(0, 3)" :key="i.id">
          <div class="item">
            <span class="index">{{ inedx + 1 }}</span>
            <span class="name">{{ i.name }}</span>
          </div>
        </template>
      </div>
    </div>
  </div>
</template>

<script setup lang="ts">
import { ref, computed, onMounted } from 'vue'
import ltAvatar from '@renderer/base-ui/lt-avatar/index.vue'
defineProps({
  item: {
    type: Object,
    default: () => ({})
  }
})

// 根据窗口大小动态调整每行显示的个数
const rowShowCount = ref(2)
const rowShowCountCpd = computed(() => {
  if (rowShowCount.value === 2) {
    return ` width: 48%;`
  } else {
    return ` width: 30%`
  }
})

// 监听主进程传递的窗口大小信息
const windowSize = () => {
  window.electron.ipcRenderer.on('window-resized', (_, { width }) => {
    console.log(22)
    if (width > 1200) {
      rowShowCount.value = 3
    } else {
      rowShowCount.value = 2
    }
  })    
}

onMounted(() => {
  windowSize()
})
</script>

<style scoped lang="scss">
.rank_top {
  width: 48%;
  padding: 10px;
  box-sizing: border-box;
  display: flex;
  flex-direction: column;
  cursor: pointer;

  .header {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: space-between;
    .title {
      padding: 0;
      margin: 0;
      font-size: 20px;
      font-weight: 700;
    }
  }

  .content {
    display: flex;
    align-items: center;
    .poster {
      width: 120px;
      height: 120px;
      position: relative;
      margin-top: 10px;
      margin-right: 10px;
      .one {
        position: absolute;
        transform: scale(0.9) translate(20px, 20px);
      }
      .two {
        position: absolute;
        transform: scale(1);
      }
    }

    .list {
      .item {
        display: flex;
        .index {
          margin-right: 10px;
        }
        .name:hover {
          color: #999;
        }
      }
    }
  }
}
</style>
